<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var domino = function (n, m, broken) {
      if (!n || !m) {
        return 0
      }
      if (broken.length == 0) {
        return ~~(nm / 2)
      }
      let matrix = new Array(m).fill(0)
      for (let i = 0; i < m; i++) {
        matrix[i] = new Array(n).fill(0)
      }
      //记录坏掉的格子
      for (let i = 0; i < broken.length; i++) {
        matrix[broken[i][1]][broken[i][0]] = 1
      }
      // console.log(matrix)
      function dfs(x, y, num) {
        while (matrix[x][y]) {
          if (x + 1 < m) {
            x = x + 1
          } else {
            x = 0;
            if (y + 1 < n) {
              y = y + 1
            } else {
              return num
            }
          }
          // console.log(x,y,num)
        }
        let max = num
        if ((x + 1) < m && !matrix[x + 1][y]) {
          max = Math.max(max, dfs(x + 1, y, num))
          matrix[x][y] = 1
          matrix[x + 1][y] = 1
          max = Math.max(dfs(x + 1, y, num + 1), max)
          matrix[x][y] = 0
          matrix[x + 1][y] = 0
        }
        if ((y + 1) < n && !matrix[x][y + 1]) {
          matrix[x][y] = 1
          matrix[x][y + 1] = 1
          max = Math.max(max, dfs(x, y, num + 1))
          matrix[x][y] = 0
          matrix[x][y + 1] = 0

        }
        return max
      }
      // 超时
      return dfs(0, 0, 0)
      // console.log(matrix)
    };
    console.log(domino(2, 3, [[1, 0], [1, 1]]));
  </script>
</body>

</html>